package com.yuou.data.logscollection.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.yuou.data.logscollection.server.entity.dto.LogsCollectionDTO;
import com.yuou.data.logscollection.server.external.kafka.client.KafkaSendClient;
import com.yuou.data.logscollection.server.service.ILogPushService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 接收其他业务系统的埋点消息
 *
 * @author hpt
 * @since 2021/4/14.
 */
@Service
public class LogPushServiceImpl implements ILogPushService {

    @Resource
    KafkaSendClient kafkaSendClient;

    /**
     * 日志推送消息队列-单个
     * @param dto
     */
    @Override
    public void push(LogsCollectionDTO dto) {
        if (BeanUtil.isNotEmpty(dto)) {
            kafkaSendClient.sendUserActionTrackMessage(dto);
        }
    }

    /**
     * 日志推送消息队列-批量
     * @param dto
     */
    @Override
    public void pushBatch(List<LogsCollectionDTO> dto) {
        if (CollUtil.isNotEmpty(dto)) {
            dto.forEach(i -> {
                kafkaSendClient.sendUserActionTrackMessage(i);
            });
        }
    }

}
